/**
 * related to userDetail.ui
 * 
 * @Author : wmn1988@qq.com
 * @Timestamp : 2016-09-21
 */
var page = sm("do_Page");
var app = sm("do_App");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var root = ui("$");
var http = require("helper/http");
var urlMall = require("url/mall");
var openHelper = require("helper/open");
var gridview = ui("gridview");
var gridData = mm("do_ListData");
gridview.bindItems(gridData);
var supplierUrl = "";

//andriod返回键
page.on("back", function() {
    app.closePage();
});

page.on("loaded", function(){
	loadSupplier();
});

var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var labelTitle = ui(addheader+".labelTitle");
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
    app.closePage();
});

function loadSupplier(){
	var data = page.getData();
	var supplierId = data.id;
	http.post(urlMall.url.supplier.detail, {id:supplierId}, function(data) {
		
		var supplierVo = data.mallSupplier;
		if(supplierVo.pathBg){
			ui("do_ImageView_2").source = supplierVo.pathBg;
		}else{
			ui("do_ImageView_2").source = supplierVo.pathBg;
		}
		ui("do_ImageView_1").source = supplierVo.pathLogo;
		labelTitle.text = supplierVo.name; 
		ui("labelName").text = supplierVo.name; 
		ui("labelRemark").text = supplierVo.resume;
		supplierUrl = supplierVo.url;
		//resume resumeImg
		/*详情图片*/
		gridData.addData(supplierVo.imgItems);
		gridview.refreshItems();
	});
};

ui("do_ALayout_2").on("touch",function(){
	if(supplierUrl){
		openHelper.open("source://view/mall/supplier/webView.ui",{url:supplierUrl});	
	}
});